#!/bin/env bash

kafka_dir=/data/kafka
kafka_tgz=/data/kafka/kafka_2.12-2.8.0.tgz
kafka_original_dir=/data/kafka/kafka_2.12-2.8.0
kafka_home=/data/kafka/kafka

export JMX_PORT=9988
echo "kafka jmx is on ${JMX_PORT}"

mk_kafka_dir() {

    kafka_dir=/data/kafka

    if [ ! -d "${kafka_dir}" ]; then
        echo "mk kafka dir"
        mkdir -p "${kafka_dir}"
    fi
}

tar_kafka() {
    if [ -f "${kafka_tgz}" ] && [ ! -d "${kafka_original_dir}" ]; then
        echo "tar kafka tgz"
        tar xf ${kafka_tgz} -C ${kafka_dir}
    fi
}

alias_kafka_dir() {
    if [ ! -d "${kafka_home}" ]; then
        ln -s ${kafka_original_dir} ${kafka_home}
    fi
}

usage() {
    echo "useage:"
    echo "-h ssh-copy-id & scp tar file"
    echo "-k setup"
    exit 0
}

while getopts 'hk' OPT; do
    case $OPT in
    k) setup_kafka "$OPTARG" ;;
    h) usage ;;
    ?) usage ;;
    esac
done


# export JMX_PORT=9988
# bin/kafka-server-start.sh -daemon config/server.properties